/**
 * @file: trans.c
 */

#include "trans.h"

uint8_t shake_hands_ack_buf[10];
uint8_t len;
/* stm32与esp32之间的握手协议 */
uint8_t shake_hands(void) {
    const char call = 'A';
    uart_write_bytes(UART_TRNAS_NUM, &call, 1);
    vTaskDelay(1000);        //等待1s stm32的应答
    uart_get_buffered_data_len(UART_TRNAS_NUM, (size_t *)&len); /* 获取环形缓冲区数据长度 */
    if(len > 0) {
        memset(shake_hands_ack_buf, 0, 10);
        uart_read_bytes(UART_TRNAS_NUM, shake_hands_ack_buf, len, 1000);
        printf("recv data is :%d\r\n", shake_hands_ack_buf[0]);
        if (shake_hands_ack_buf[0] == 'B')
        {
            return 1;
        }
    }

    return 0;
}

/**
 * 双mcu之间的串口交互函数
 */
void trans_func(void)
{

}